$(function () {
    $("#jqGrid").jqGrid({
        url: baseURL + 'sys/apply/list',
        datatype: "json",
        colModel: [			
			{ label: '申请人', name: 'userName', width: 75 },
            { label: '申请角色', name: 'remark', sortable: false, width: 75 },
			{ label: '申请人部门', name: 'deptName', width: 90 },
			{ label: '状态', name: 'auditFlag', width: 60, formatter: function(value, options, row){
				// return value === '0' ?
				// 	'<span class="label label-danger">未审核</span>' :
				// 	'<span class="label label-success">已审核</span>';
				return value === '0' ?
					'<span style="color: #d9534f;">未审核</span>' :
					'<span style="color: #5cb85c;">已审核</span>';
			}},
			{ label: '申请时间', name: 'createTime', width: 85}
        ],
		viewrecords: true,
        height: 385,
        rowNum: 10,
		rowList : [10,30,50],
        rownumbers: true, 
        rownumWidth: 25, 
        autowidth:true,
        multiselect: true,
        pager: "#jqGridPager",
        jsonReader : {
            root: "page.list",
            page: "page.currPage",
            total: "page.totalPage",
            records: "page.totalCount"
        },
        prmNames : {
            page:"page", 
            rows:"limit", 
            order: "order"
        },
        gridComplete:function(){
        	//隐藏grid底部滚动条
        	$("#jqGrid").closest(".ui-jqgrid-bdiv").css({ "overflow-x" : "hidden" }); 
        }
    });
});

var vm = new Vue({
	el:'#rrapp',
    data:{
        /*q:{
            username: null
        },
        showList: true,
        title:null,
        roleList:{},
        user:{
            status:1,
            deptId:null,
            deptName:null,
            roleIdList:[]
        }*/
    },
    methods: {
        /*query: function () {
            vm.reload();
        },*/
    	apply: function () {
            var id = getSelectedRows();
            if(id == null){
                return ;
            }
            var ids = '';
            for(var i = 0; i < id.length; i++){
            	ids += id[i] + ',';
            }
            $.ajax({
            	url : '../../sys/apply/apply',
            	type: 'post',
            	dataType: 'json',
            	data:{
            		ids : ids
            	},
            	success: function(result){
            		debugger
            		if(result.code == 0){
            			alert('审核成功');
            			vm.reload();
            		}else{
            			alert(result.msg);
            		}
            	},
            	error : function(result){
            		alert('审核失败!');
            	}
            });
        },
        
        reload: function () {
            vm.showList = true;
            var page = $("#jqGrid").jqGrid('getGridParam','page');
            $("#jqGrid").jqGrid('setGridParam',{
                page:page
            }).trigger("reloadGrid");
        }
    }
});